package com.aliyun.messagemgt.common.dto.send;

import com.alibaba.fastjson.JSONObject;
import com.aliyun.messagemgt.common.annotation.CustomAnnotation;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;

/**
 * @ClassName: MsgPushDTO
 * @Description:
 * @Author: wugongzi
 * @Date: 2021/9/14 15:44
 * @Version: 1.0
 */
@Getter
@Setter
@ToString
@ApiModel("消息推送")
public class MsgPushDTO implements Serializable {
    private static final long serialVersionUID = -7578676900211197805L;

    @Valid
    @NotEmpty(message = "msgRecordList 不为空")
    @CustomAnnotation(name = "msgRecordList", desc = "消息体列表")
    @ApiModelProperty("消息列表")
    private List<MsgRecordDTO> msgRecordList;

    @Getter
    @Setter
    @ToString
    @ApiModel("消息记录")
    public static class MsgRecordDTO implements Serializable {
        private static final long serialVersionUID = -4835772484308194743L;

        @NotBlank(message = "orgMessageId 不为空")
        @CustomAnnotation(name = "orgMessageId", desc = "源端系统消息ID")
        @ApiModelProperty("源端系统消息ID(源端系统唯一)")
        private String orgMessageId;

        @CustomAnnotation(name = "tenantCode", desc = "租户编码")
        @ApiModelProperty("租户编码")
        private String tenantCode;

        @CustomAnnotation(name = "userId", desc = "用户id")
        @ApiModelProperty("userId")
        private String userId;

        @NotBlank(message = "sceneCode 不为空")
        @CustomAnnotation(name = "sceneCode", desc = "业务场景编码")
        @ApiModelProperty("场景编码，组件前端维护")
        private String sceneCode;

        @NotNull(message = "messageInfo 不为空")
        @CustomAnnotation(name = "messageInfo", desc = "消息信息")
        @Valid
        @ApiModelProperty("消息信息")
        private MessageInfo messageInfo;

        @CustomAnnotation(name = "receiveChannelCodes", desc = "接收渠道编码清单")
        @ApiModelProperty("接收渠道编码清单(最多10个)")
        private List<String> receiveChannelCodes;

        @NotNull(message = "receiveRangeInfo 不为空")
        @CustomAnnotation(name = "receiveRangeInfo", desc = "接收范围信息")
        @Valid
        @ApiModelProperty("接收范围信息")
        private ReceiveRangeInfo receiveRangeInfo;

        @CustomAnnotation(name = "failureResendTimes", desc = "失败重发次数")
        @Min(value = 1,message = "failureResendTimes 最小为1")
        @ApiModelProperty("失败重发次数,最小为1,默认不重试")
        private Integer failureResendTimes;

        @CustomAnnotation(name = "failureResendInterval", desc = "失败重发时间间隔")
        @Min(value = 1,message = "failureResendInterval 最小为1")
        @ApiModelProperty("失败重发时间间隔,单位：分钟,最小为1,配置失败重发次数后有效")
        private Integer failureResendInterval;

        @Getter
        @Setter
        @ToString
        @ApiModel("消息信息")
        public static class MessageInfo implements Serializable {

            private static final long serialVersionUID = -4741853913463522128L;
            @NotBlank(message = "messageTransType 不为空")
            @CustomAnnotation(name = "messageTransType", desc = "消息传输类型")
            @ApiModelProperty("消息传输类型：CONTENT-传内容，TEMPLATE-传模板，LINK_CARD-卡片链接")
            private String messageTransType;

            @CustomAnnotation(name = "messageContent", desc = "消息内容")
            @ApiModelProperty("消息内容")
            private String messageContent;

            @Valid
            @CustomAnnotation(name = "linkCard", desc = "链接卡片信息")
            @ApiModelProperty("链接卡片信息")
            private LinkCard linkCard;

            @CustomAnnotation(name = "messageSubject", desc = "消息主题")
            @ApiModelProperty("消息主题")
            private String messageSubject;

            @CustomAnnotation(name = "messageAttachment", desc = "消息附件")
            @ApiModelProperty("消息附件")
            private String messageAttachment;

            @CustomAnnotation(name = "templateCode", desc = "模板编码")
            @ApiModelProperty("模板编码")
            private String templateCode;

            @CustomAnnotation(name = "templateParams", desc = "模板参数")
            @ApiModelProperty("模板参数")
            private JSONObject templateParams;
        }

        @Getter
        @Setter
        @ToString
        @ApiModel("消息接收范围信息")
        public static class ReceiveRangeInfo implements Serializable {
            private static final long serialVersionUID = 6213948695707219839L;

            @NotBlank(message = "rangeTransType 不为空")
            @CustomAnnotation(name = "rangeTransType", desc = "范围传输方式")
            @ApiModelProperty("范围传输方式：GROUP-按分组，CUST-按报文自定义")
            private String rangeTransType;

            @CustomAnnotation(name = "receiveGroupCodes", desc = "接收组编码清单")
            @ApiModelProperty("接收组编码清单（最多10个）")
            private List<String> receiveGroupCodes;

            @CustomAnnotation(name = "rangeType", desc = "范围类型")
            @ApiModelProperty("范围类型：ORG-组织，POS-职位，ROLE-角色，USERID-用户ID，PHONE-用户手机号，EMAIL-用户邮箱")
            private String rangeType;

            @CustomAnnotation(name = "rangeValues", desc = "范围值列表")
            @ApiModelProperty("范围值列表：组织ID/职位ID/角色ID/用户ID/手机号/邮箱")
            private List<String> rangeValues;
        }
    }

    @Data
    @ApiModel("卡片消息内容")
    public static class LinkCard implements Serializable {
        private static final long serialVersionUID = -4835772484308194743L;


        @NotBlank(message = "title 不为空")
        @CustomAnnotation(name = "title", desc = "卡片标题")
        private String title;

        @NotBlank(message = "description 不为空")
        @CustomAnnotation(name = "description", desc = "卡片描述")
        private String description;

        @NotBlank(message = "iconLink 不为空")
        @CustomAnnotation(name = "iconLink", desc = "卡片链接")
        private String iconLink;

        @NotBlank(message = "link 不为空")
        @CustomAnnotation(name = "link", desc = "卡片跳转链接")
        private String link;

        @CustomAnnotation(name = "pcLink", desc = "PC端卡片跳转链接")
        private String pcLink;

        private String fromName;

        private String fromIconLink;
    }
}
